home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / gamma-bros.swf / scripts / __Packages / classes / fx / Asteroid.as next >
Encoding:
Text File  |  2011-10-17  |  8.5 KB  |  248 lines

  1. class classes.fx.Asteroid
  2. {
  3.    var size;
  4.    var id;
  5.    var x;
  6.    var y;
  7.    var dir;
  8.    var colorV;
  9.    var power;
  10.    var clip;
  11.    var feeler;
  12.    var xMov;
  13.    var yMov;
  14.    var c = 0;
  15.    var sizeArray = [[1,3],[4,9],[10,17],[18,23],[24,27]];
  16.    var yank = false;
  17.    var feelerCount = 0;
  18.    var feelerBreak = false;
  19.    var fast = false;
  20.    function Asteroid(px, py, psize, pdir, pcolorV, pid, pfast)
  21.    {
  22.       this.size = psize;
  23.       this.id = pid;
  24.       this.x = px;
  25.       this.y = py;
  26.       this.dir = pdir;
  27.       this.colorV = pcolorV;
  28.       this.power = this.size * 6;
  29.       this.fast = pfast;
  30.       _root.d = _root.d + 1;
  31.       this.clip = _root.attachMovie("asteroid","asteroid" + this.id + "Clip",_root.d + 75000);
  32.       this.clip.gotoAndStop(this.colorV);
  33.       this.clip.body.gotoAndStop(_root.randRange(this.sizeArray[this.size - 1][0],this.sizeArray[this.size - 1][1]));
  34.       if(!_root.astField)
  35.       {
  36.          _root.d = _root.d + 1;
  37.          this.feeler = this.clip.attachMovie("asteroidFeeler","asteroidFeeler" + this.id,_root.d + 75000);
  38.          this.feeler._x = -100;
  39.          this.feeler._y = -100;
  40.          this.feeler._width = 50 + this.clip.body._width;
  41.          this.feeler._height = 50 + this.clip.body._height;
  42.       }
  43.       if(this.dir == "U")
  44.       {
  45.          this.xMov = _root.randRange2(this.size - 9,-1 * (this.size - 9));
  46.          this.yMov = _root.randRange2(this.size - 9,0);
  47.       }
  48.       else if(this.dir == "D")
  49.       {
  50.          this.xMov = _root.randRange2(this.size - 9,-1 * (this.size - 9));
  51.          this.yMov = _root.randRange2(0,-1 * (this.size - 9));
  52.       }
  53.       else if(this.dir == "L")
  54.       {
  55.          this.xMov = _root.randRange2(this.size - 9,0);
  56.          this.yMov = _root.randRange2(this.size - 9,-1 * (this.size - 9));
  57.       }
  58.       else
  59.       {
  60.          this.xMov = _root.randRange2(0,-1 * (this.size - 9));
  61.          this.yMov = _root.randRange2(this.size - 9,-1 * (this.size - 9));
  62.       }
  63.       if(this.fast)
  64.       {
  65.          this.xMov *= 0.4;
  66.          this.yMov *= 2.5;
  67.       }
  68.       this.xMov *= _root.dif.speed;
  69.       this.yMov *= _root.dif.speed;
  70.       this.clip._x = this.x;
  71.       this.clip._y = this.y;
  72.       this.clip._rotation = random(4) * 90;
  73.    }
  74.    function bombed()
  75.    {
  76.       _root.createExploA([this.x,this.y,this.size * 20 + 40,_root.randRange(75,100)]);
  77.       this.yank = true;
  78.    }
  79.    function main()
  80.    {
  81.       this.c = this.c + 1;
  82.       if(this.clip.body.hitTest(_root[_root.char + "Clip"]))
  83.       {
  84.          _root[_root.char].hit(this.xMov,this.yMov,100,this.power);
  85.          _root.createExploA([this.x,this.y,this.size * 20 + 40,_root.randRange(75,100)]);
  86.          var _loc7_ = !(this.size == 2 || this.size == 4) ? this.size : this.size - 1;
  87.          _root.audio.playLevel4("astX" + _loc7_ + "_" + (random(2) + 1),_root.randRange(25,45));
  88.          if(this.size > 2)
  89.          {
  90.             if(this.size == 5)
  91.             {
  92.                if(random(2) > 0)
  93.                {
  94.                   _root.createPowerUp([this.x,this.y,"gem" + _root.randRange(1,6)]);
  95.                }
  96.             }
  97.             this.size -= 1;
  98.             var _loc4_ = _root.randRange(1,2);
  99.             var _loc3_ = 0;
  100.             while(_loc3_ < _loc4_)
  101.             {
  102.                _root.createAsteroid([this.x,this.y,this.size,tempDir,this.colorV]);
  103.                _loc3_ = _loc3_ + 1;
  104.             }
  105.          }
  106.          this.yank = true;
  107.       }
  108.       _loc3_ = 0;
  109.       var _loc8_ = _root.broShots.length;
  110.       while(_loc3_ < _loc8_)
  111.       {
  112.          var _loc5_ = _root.broShots[_loc3_] + "Clip";
  113.          if(this.clip.body.hitTest(_root[_loc5_]))
  114.          {
  115.             _root.createExploA([this.x,this.y,this.size * 20 + 40,_root.randRange(75,100)]);
  116.             _loc7_ = !(this.size == 2 || this.size == 4) ? this.size : this.size - 1;
  117.             _root.audio.playLevel4("astX" + _loc7_ + "_" + (random(2) + 1),_root.randRange(25,45));
  118.             _root[_root.char].fc = _root[_root.char].fireFreq - _root.rapidVar - 1;
  119.             var _loc6_ = _root.broShots[_loc3_];
  120.             _root[_loc6_].exploX = this.x + this.clip.body._width / 2;
  121.             _root[_loc6_].exploY = this.y + this.clip.body._height / 2;
  122.             var tempDir = _root[_loc6_].dir;
  123.             _root[_loc6_].hit();
  124.             if(this.size > 2)
  125.             {
  126.                if(this.size == 5)
  127.                {
  128.                   if(random(2) > 0)
  129.                   {
  130.                      _root.createPowerUp([this.x,this.y,"gem" + _root.randRange(1,6)]);
  131.                   }
  132.                }
  133.                this.size -= 1;
  134.                _loc4_ = _root.randRange(1,2);
  135.                _loc3_ = 0;
  136.                while(_loc3_ < _loc4_)
  137.                {
  138.                   _root.createAsteroid([this.x,this.y,this.size,tempDir,this.colorV]);
  139.                   _loc3_ = _loc3_ + 1;
  140.                }
  141.             }
  142.             this.yank = true;
  143.             break;
  144.          }
  145.          _loc3_ = _loc3_ + 1;
  146.       }
  147.       if(!_root.astField)
  148.       {
  149.          _loc3_ = 0;
  150.          _loc8_ = _root.enemyShots.length;
  151.          while(_loc3_ < _loc8_)
  152.          {
  153.             _loc5_ = _root.enemyShots[_loc3_] + "Clip";
  154.             if(this.clip.body.hitTest(_root[_loc5_]))
  155.             {
  156.                _root.createExploA([this.x,this.y,this.size * 20 + 40,_root.randRange(75,100)]);
  157.                _loc7_ = !(this.size == 2 || this.size == 4) ? this.size : this.size - 1;
  158.                _root.audio.playLevel4("astX" + _loc7_ + "_" + (random(2) + 1),_root.randRange(25,45));
  159.                _loc6_ = _root.enemyShots[_loc3_];
  160.                var tempDir = _root[_loc6_].dir;
  161.                _root[_loc6_].hit(this.size);
  162.                if(this.size > 2)
  163.                {
  164.                   if(this.size == 5)
  165.                   {
  166.                      if(random(2) > 0)
  167.                      {
  168.                         _root.createPowerUp([this.x,this.y,"gem" + _root.randRange(1,6)]);
  169.                      }
  170.                   }
  171.                   this.size -= 1;
  172.                   _root.createAsteroid([this.x,this.y,this.size,tempDir,this.colorV]);
  173.                }
  174.                this.yank = true;
  175.                break;
  176.             }
  177.             _loc3_ = _loc3_ + 1;
  178.          }
  179.          if(random(3) == 0)
  180.          {
  181.             _loc3_ = 0;
  182.             _loc8_ = _root.chars.length;
  183.             while(_loc3_ < _loc8_)
  184.             {
  185.                _loc5_ = _root.chars[_loc3_] + "Clip";
  186.                if(!this.feelerBreak)
  187.                {
  188.                   if(this.feeler.hitTest(_root[_loc5_]))
  189.                   {
  190.                      _loc6_ = _root.chars[_loc3_];
  191.                      _root[_loc6_].evade();
  192.                      this.feelerCount = 0;
  193.                      this.feelerBreak = true;
  194.                   }
  195.                }
  196.                if(this.clip.body.hitTest(_root[_loc5_]))
  197.                {
  198.                   _root.createExploA([this.x,this.y,this.size * 20 + 40,_root.randRange(75,100)]);
  199.                   _loc7_ = !(this.size == 2 || this.size == 4) ? this.size : this.size - 1;
  200.                   _root.audio.playLevel4("astX" + _loc7_ + "_" + (random(2) + 1),_root.randRange(25,45));
  201.                   _loc6_ = _root.chars[_loc3_];
  202.                   var tempDir = _root[_loc6_].dir;
  203.                   _root[_loc6_].bombed(this.power);
  204.                   if(this.size > 2)
  205.                   {
  206.                      if(this.size == 5)
  207.                      {
  208.                         if(random(2) > 0)
  209.                         {
  210.                            _root.createPowerUp([this.x,this.y,"gem" + _root.randRange(1,6)]);
  211.                         }
  212.                      }
  213.                      this.size -= 1;
  214.                      _root.createAsteroid([this.x,this.y,this.size,tempDir,this.colorV]);
  215.                   }
  216.                   this.yank = true;
  217.                   break;
  218.                }
  219.                _loc3_ = _loc3_ + 1;
  220.             }
  221.             if(this.feelerBreak)
  222.             {
  223.                this.feelerCount = this.feelerCount + 1;
  224.                if(this.feelerCount == 5)
  225.                {
  226.                   this.feelerBreak = false;
  227.                }
  228.             }
  229.          }
  230.       }
  231.       if(this.c > 100)
  232.       {
  233.          if(this.x > 1050 || this.x < -50 || this.y < -50 || this.y > 650)
  234.          {
  235.             this.yank = true;
  236.          }
  237.       }
  238.       if(this.yank)
  239.       {
  240.          _root.removeFX("asteroid" + this.id);
  241.       }
  242.       this.x += this.xMov;
  243.       this.y += this.yMov;
  244.       this.clip._x = this.x;
  245.       this.clip._y = this.y;
  246.    }
  247. }
  248.